<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.model.JobPost"%>
<%@page import="com.shsh.safemanage.dao.TitlePostManageGroupDao"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.PostcheckPattern"%>
<%@page import="com.shsh.safemanage.model.PostcheckContent"%>
<%@page import="com.shsh.safemanage.model.PostcheckStandard"%>
<%@page import="com.shsh.safemanage.model.ProblemTransfer"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.RequestUtil"%>

<%
session.removeAttribute(Constants.SESSION_MANAGE_GROUP_USER);
session.removeAttribute(Constants.SESSION_PROBLEM_DEPARTMENT1);

Integer problemType = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_PROBLEM_TYPE, (Integer)null);
String problemName = Problem.getProblemName(problemType);

String problemIDStr = request.getParameter(Constants.REQUEST_PARAMETER_ID);
Long problemID = 0L;
try {
	problemID = new Long(problemIDStr);
} catch (Exception e) {
}

String transferIDStr = request.getParameter(Constants.REQUEST_PARAMETER_TRANSFER_ID);
Long transferID = 0L;
try {
	transferID = new Long(transferIDStr);
} catch (Exception e) {
}

String fromPage = request.getParameter(Constants.REQUEST_PARAMETER_FROM_PAGE);

DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
ProblemDao problemDao = DaoCreator.createProblemDao();
PostCheckDao postcheckDao = DaoCreator.createPostCheckDao();
TitlePostManageGroupDao titlePostManageGroupDao = DaoCreator.createTitlePostManageGroupDao();
WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();
UserAction userAction = ActionCreator.createUserAction();

Problem problem = problemDao.getProblemByID(problemID);

PostCheck postcheck = null;
PostcheckPattern postcheckPattern = null; 
PostcheckContent postcheckContent = null; 
PostcheckStandard postcheckStandard = null; 

if(problem.getProblemType() == Constants.PROBLEM_TYPE_POSTCHECK) {
	postcheck = postcheckDao.getPostCheck(problem.getPostcheckID());
	postcheckPattern = postcheckDao.getPostcheckPatternByID(problem.getPostcheckPatternID());
	postcheckContent =  postcheckDao.getPostcheckContentByID(problem.getPostcheckContentID());
	postcheckStandard = postcheckDao.getPostcheckStandardByID(problem.getPostcheckStandardID());
}

User user = (User) session.getAttribute(Constants.SESSION_USER);
JobPost post1 = titlePostManageGroupDao.getJobPostByID(user.getJobPost1ID());
JobPost post2 = titlePostManageGroupDao.getJobPostByID(user.getJobPost2ID());
JobPost post3 = titlePostManageGroupDao.getJobPostByID(user.getJobPost3ID());
Role theRole = userAction.getUserRole(request);

int role = writeProblemAction.calRole(post1, post2, post3, theRole);
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; <%=problemName %>填报
</div>

<div class="tt">问题浏览及反馈卡</div>
<div class="content">
	<%@include file="/problem_detail_section.jsp"%>
	<table align="center" border="1" width="99%" cellpadding="0"
		cellspacing="0">
		<%--
		<tr>
			<td class="td1">
				<span style="margin-left: 30px; font-weight: bold">通报内容标题：</span>
				<%=problem.getProblemTitle()%>
			</td>
		</tr>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px; font-weight: bold">通报内容：</span>
				<br />
				<span style="margin-left: 30px">问题内容：</span>
				<%=problem.getProblemContent()%>
				<br />
				<span style="margin-left: 30px">整改措施：</span>
				<%=problem.getProblemZhenggai()%>
			</td>
		</tr>
		 --%>
		<%if(problem.getProblemType() == Constants.PROBLEM_TYPE_POSTCHECK) {%>
		<tr id="postcheckTR">
			<td class="td1">
			<span style="margin-left: 30px" class="span1">岗检：</span><%=postcheck.getCheckName() %>
			<br/>
			<span style="margin-left: 30px" class="span1">检查方式：</span><%=postcheckPattern.getPattern() %>
			<br/>
			<span style="margin-left: 30px" class="span1">工作内容：</span><%=postcheckContent.getContent() %>
			<br/>
			<span style="margin-left: 30px" class="span1">工作标准与要求：</span><%=postcheckStandard.getStandard() %>
			<br/>
			<span style="margin-left: 30px" class="span1">扣分值：</span><%=problem.getGrade() == null ? "&nbsp;":Util.formatGrade(problem.getGrade()) %>
			<br/>
			<span style="margin-left: 30px" class="span1">要求整改完成日期：</span><%=Util.formatDate(problem.getCompleteDate()) %>
			</td>
		</tr>
		<%} %>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px" class="span1">填报人及时间：</span>
				<span><%=user.getDepartment1Name()%>-<%=user.getDepartment2Name()%>-<%=user.getDepartment3Name()%></span>
				<span><%=user.getName()%></span>
				<span><%=Util.formatDateTime(Calendar.getInstance())%></span>
			</td>
		</tr>
		<tr>
			<td class="td1" align="center">
				<% if(!"postcheckReport".equals(fromPage)) {%>
				<input type="button" value="输出为<%=problemName %>报告" onclick="convertProblem()" />
				<%} %>
				<input type="button" value="取 消" style="margin-left: 20px" onclick="cancelFeedback()" />
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">
function convertProblem() {
	loadPageSection(
			'<%=request.getContextPath()%>/shutdown/convert_problem.jsp', 
			'mainContentDiv', 
			{
				problemType: <%=problemType%>,
				id: <%=problem.getId()%>
			}, 
			true
			);
}

function feedback() {
	var feedback = getElementValueByID('feedback');
	if (feedback == '') {
		$.dialog.alert('请输入反馈意见');
		return;
	}
	
	var processMethod = 0;
	var processRadio0 = document.getElementById('processRadio0');
	var processRadio1 = document.getElementById('processRadio1');
	var processRadio2 = document.getElementById('processRadio2');
	var processRadio3 = document.getElementById('processRadio3');
	var processRadio4 = document.getElementById('processRadio4');
	var processRadio5 = document.getElementById('processRadio5');
	var processRadio6 = document.getElementById('processRadio6');
	if (processRadio1 != null && processRadio1.checked) {
		processMethod = 1;
	} else if (processRadio2 != null && processRadio2.checked) {
		processMethod = 2;
	} else if (processRadio3 != null && processRadio3.checked) {
		processMethod = 3;
	} else if (processRadio4 != null && processRadio4.checked) {
		processMethod = 4;
	} else if (processRadio5 != null && processRadio5.checked) {
		processMethod = 5;
	} else if (processRadio6 != null && processRadio6.checked) {
		processMethod = 6;
	} else if (processRadio0 != null && processRadio0.checked) {
		processMethod = 0;
	}
	
	var userIDs = '';
	var userIDElements = document.getElementsByName('informedUserID');
	for (var i = 0; i != userIDElements.length; i++) {
		var userIDEle = userIDElements[i];
		if (userIDEle.checked) {
			if (userIDs == '') {
				userIDs = userIDs + userIDEle.value;
			} else {
				userIDs = userIDs + ',' + userIDEle.value;
			}
		}
	}
	
	var manageGroupUserCheckEles = document.getElementsByName('manageGroupUserCheck');
	for (var i = 0; i != manageGroupUserCheckEles.length; i++) {
		if (manageGroupUserCheckEles[i].checked) {
			if (userIDs == '') {
				userIDs = userIDs + manageGroupUserCheckEles[i].value;
			} else {
				userIDs = userIDs + ',' + manageGroupUserCheckEles[i].value;
			}
		}
	}
	
	$.dialog.confirm('您确定输出为<%=problemName %>报告？', function() {
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'<%=request.getContextPath()%>/shutdown/convert_problem.jsp',
			data:{
				problemType: <%=problemType%>,
				processMethod: processMethod,
				id: <%=problemID%>,
				feedback: getElementValueByID('feedback'),
				transferID: <%=transferID%>,
				userID: userIDs
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('问题反馈成功！', function() {
							loadPageSection(
									'<%=request.getContextPath()%>/shutdown/problem_browse.jsp', 
									'mainContentDiv', 
									{
										fromPage: 'feedback'
									}
								);
						});
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	});
}

function cancelFeedback() {
	$.dialog.confirm('您确定取消此次输出吗？', function() {
		loadPageSection(
				'<%=request.getContextPath()%>/shutdown/problem_browse.jsp', 
				'mainContentDiv', 
				{
					problemType: <%=problemType%>,
					fromPage: 'feedback'
				}
				);
	}, function(){});
}

function chooseProcessMethod(method) {
	if (method == 1) {
		document.getElementById('informedPersonsTR').style.display = 'none';
		document.getElementById('feedback').readonly = true;
		setElementValueByID('feedback', '<%=user.getDepartment1Name()%>，<%=user.getJobPost1Name()%><%=user.getName()%>确认该问题已整改');
	} else if (method == 2) {
		document.getElementById('informedPersonsTR').style.display = '';
		document.getElementById('feedback').readonly = false;
		setElementValueByID('feedback', '');
	} else if (method == 4 || method == 3 || method == 5 || method == 6 || method == 0) {
		document.getElementById('informedPersonsTR').style.display = 'none';
		setElementValueByID('feedback', '');
	}
}
</script>
